<template>
    <div>
        <h3>角色管理</h3>
        <el-table
                :data="tableData.slice((currentPage-1)*PageSize,currentPage*PageSize)"
                style="width: 100%">
            <el-table-column
                    label="角色名称"
                    prop="solename">
            </el-table-column>
            <el-table-column
                    align="right">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="findById(scope.row.soleId)">查看详情
                    </el-button>
                    <el-button
                            size="mini"
                            @click="change(scope.row.soleId)">修改
                    </el-button>
                    <el-button
                            size="mini"
                            @click="del(scope.row.soleId)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="tabListPage">
            <el-pagination @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="currentPage"
                           :page-sizes="pageSizes"
                           :page-size="PageSize" layout="total, sizes, prev, pager, next, jumper"
                           :total="totalCount">
            </el-pagination>
        </div>

        <el-button type="primary" @click="add" style="margin: 20px;">添加</el-button>

    </div>
</template>

<script>
    export default {
        name: "RoleView",

        data() {
            return {
                soleId:'',
                tableData:[],
                name: '',
                totalCount:null,

                // 默认显示第几页
                currentPage:1,
                // 个数选择器（可修改）
                pageSizes:[1,2,3,4],
                // 默认每页显示的条数（可修改）
                PageSize:3,
            }
        },
        mounted() {
            this.init()
        },

        methods: {
            init(){
                this.$axios.get("api/sole/findAll").then(r =>{
                    console.log(r.data)
                    this.tableData = r.data;
                })
            },
            findById(id) {
                this.$store.state.soleid = id
                this.$router.push("SelectRolePower")
            },

            del(id) {
                console.log(id);
                this.$axios.get("api/sole/del?id="+id).then( r =>{
                    console.log(r.data);
                    if(r.data==true){
                        this.init();
                    }
                    else {
                        this.$message.error("删除失败")
                    }
                })
            },
            change(id) {
                this.$store.state.soleid = id
                this.$router.push("UpdateRolePower")
            },

            add() {

            },

            handleSizeChange(size) {
                // 改变每页显示的条数
                this.PageSize=size
                // 注意：在改变每页显示的条数时，要将页码显示到第一页
                this.currentPage=1
            },
            // 显示第几页
            handleCurrentChange(size) {
                // 改变默认的页数
                this.currentPage=size
            },
        },
    }
</script>

<style scoped>

</style>